﻿/////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2009 Eric Bowen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and 
// associated documentation files (the "Software"), to deal in the Software without restriction, including 
// without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
// copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the 
// following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial 
// portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/////////////////////////////////////////////////////////////////////////////////////////////////////
// Author's blog: http://blog.scrappydog.com
// Updated source code available:  http://scrappydb.codeplex.com
/////////////////////////////////////////////////////////////////////////////////////////////////////

using System;
using ScrappyDB.BaseClasses;

namespace ScrappyDB.Membership
{
    public class UserInRole : SdbEntity
    {
        private Guid _roleId;
        private Guid _userId;
        private string _userInRoleId;

        /// <summary>
        /// UserInRoleId is a concatinated string that combines the UserId and RoleId with and underscore seperator.
        /// 
        /// Example: "DD95386E-5F0A-477f-887F-6F5B243C0323_2C33842B-3EF8-4293-9EE8-868437D7E8EC".
        /// The purpose of this to easily avoid duplicates
        /// </summary>
        public string UserInRoleId
        {
            get { return _userInRoleId; }
            set { _userInRoleId = value; }
        }

        public Guid UserId
        {
            get { return _userId; }
            set
            {
                _userId = value;
                GenerateId();
            }
        }

        public Guid RoleId
        {
            get { return _roleId; }
            set
            {
                _roleId = value;
                GenerateId();
            }
        }

        private void GenerateId()
        {
            _userInRoleId = _userId + "_" + _roleId;
        }
    }
}